unit uBaseCompThread;

interface

uses
  System.Classes, System.UITypes, Vcl.ComCtrls, Vcl.StdCtrls, Vcl.Dialogs,
  Vcl.ExtCtrls;

type
  TBaseCompThread = class(TThread)
  private
    ProgressBar: TProgressBar;
    StatusBar: TStatusBar;
    LoadExcelFileBtn: TButton;
    UpdateBtn: TButton;
    PageControl: TPageControl;
    InsPanel: TPanel;
  protected
    PBStyle: TProgressBarStyle;
    StatusText: string;
    Enabled: Boolean;
    DialogMessage: string;

    procedure SetProgressBarStyle;
    procedure SetStatusBarText;
    procedure ChangeControlAvailability;
    procedure ShowErrorDialog;
    procedure ShowInfoDialog;
  public
    constructor Create(CreateSuspended: Boolean; ProgressBar: TProgressBar;
      StatusBar: TStatusBar; PageControl: TPageControl; LoadExcelFileBtn,
      UpdateBtn: TButton; InsPanel: TPanel); overload;
  end;

implementation

// TBaseCompThread
// Базовый класс потока

constructor TBaseCompThread.Create(CreateSuspended: Boolean; ProgressBar:
  TProgressBar; StatusBar: TStatusBar; PageControl: TPageControl;
  LoadExcelFileBtn, UpdateBtn: TButton; InsPanel: TPanel);
begin
  inherited Create(CreateSuspended);

  Self.ProgressBar := ProgressBar;
  Self.StatusBar := StatusBar;
  Self.LoadExcelFileBtn := LoadExcelFileBtn;
  Self.UpdateBtn := UpdateBtn;
  Self.PageControl := PageControl;
  Self.InsPanel := InsPanel;
end;

procedure TBaseCompThread.ChangeControlAvailability;
begin
  // Изменение доступности элементов интерфейса через переменную Enabled
  Self.LoadExcelFileBtn.Enabled := Self.Enabled;
  Self.UpdateBtn.Enabled := Self.Enabled;
  Self.PageControl.Enabled := Self.Enabled;
  Self.InsPanel.Enabled := Self.Enabled;
end;

procedure TBaseCompThread.SetStatusBarText;
begin
  // Вывод текста в StatusBar
  StatusBar.Panels[0].Text := StatusText;
end;

procedure TBaseCompThread.SetProgressBarStyle;
begin
  // Изменение стиля ProgressBar
  ProgressBar.Style := PBStyle;
end;

procedure TBaseCompThread.ShowErrorDialog;
begin
  // Отправка сообщения с ошибкой
  MessageDlg(Self.DialogMessage, mtError, [mbOK], 0);
end;

procedure TBaseCompThread.ShowInfoDialog;
begin
  // Отправка сообщения с ошибкой
  MessageDlg(Self.DialogMessage, mtInformation, [mbOK], 0);
end;

end.

